package Offer.offer2017;

/**
 * Created by 雷文康 on 2018/1/1.
 */
public class Test24 {
    public static void main(String[] args) {
        int[] array = {5, 7, 6, 9, 11, 10, 8};
        System.out.println(isBST(array));
    }

    public static boolean isBST(int[] array) {
        if (array == null || array.length == 0) {
            return false;
        }
        return isBST(array, 0, array.length - 1);
    }

    public static boolean isBST(int[] array, int start, int end) {
        if (start == end) {
            return true;
        }
        int i;
        for (i = start; i < end; i++) {
            if (array[i] > array[end]) {
                break;
            }
        }
        for (int j = i; j < end; j++) {
            if (array[j] <= array[end]) {
                return false;
            }
        }
        return isBST(array, start, i - 1) && isBST(array, i, end - 1);
    }
}
